package fileProcessors.implementations;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.security.InvalidParameterException;

import fileProcessors.FileProcessor;

public class MapleOptimizedCodeOptimizer extends FileProcessor {

	@Override
	public void processFiles(File[] files, File outputDirectory, File outputFile)  {
		if(files.length>1){
			throw new InvalidParameterException("too many files...only one is supported...");
		}
		
		for(File file:files){
			try {
				BufferedReader br=new BufferedReader(new FileReader(file));
				BufferedWriter bw=new BufferedWriter(new FileWriter(new File(outputDirectory, file.getName()+"modified.txt")));
				String line;
				//definition of a line like "   t2239 = .........;
				String pat="\\w*?t\\d+.+?;";
				while((line=br.readLine())!=null){
					if(line.matches(pat)){
						line="double "+line;
					}
					bw.write(line);
					bw.newLine();
				}
				br.close();
				bw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	@Override
	public String getInformation() {
		// TODO Auto-generated method stub
		return "info";
	}

	@Override
	public String getDate() {
		// TODO Auto-generated method stub
		return "heute";
	}

}
